#include "Graph.h"
#include "Simple_window.h"
#include <vector>
#include <iostream>

using namespace Graph_lib;
using namespace std;

const int		MAX_X = 600;
const int		MAX_Y = 400;
const double	PI    = 3.14159265; 

void draw_regular_poly(Graph_lib::Closed_polyline&, Point , int, int, double);

int main()
{
	try
	{
		Point t1(100,100);
		Simple_window win (t1, 600, 400, "ex_1");
		Point center(MAX_X/2, MAX_Y/2);
		int radius = 50;
		double angle = PI/2;
		for (int i = 3; i <= 30; ++i)
		{
			Graph_lib::Closed_polyline *poly = new Graph_lib::Closed_polyline;
			draw_regular_poly(*poly, center, i, radius, angle);
			win.attach(*poly);
			radius = int(radius/cos(PI/i));
			angle+=PI/i;
			ostringstream os;
			os << i;
			win.set_label(os.str());
			win.wait_for_button();
		}
	}
	catch (exception& e)
	{
		cerr << e.what() << endl;
		system("pause");
		return 1;
	}
	catch(...)
	{
		cerr << "Unknown exception" << endl;
		system("pause");
		return 2;
	}
}

void draw_regular_poly(Graph_lib::Closed_polyline& poly, Point center, int N, int radius, double angle = 0)
{
	for (double fi = 0; fi < 2*PI; fi+=2*PI/N)
	{
		int px = int(center.x+radius*cos(fi+angle));
		int py = int(center.y-radius*sin(fi+angle));
		poly.add(Point(px, py));
	}
}


